// pages/contract/contract.js
let app = getApp();
let testAddr = app.globalData.testAddr;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    login: [
      { id: "0", logname: "我的合同" },
      { id: "1", logname: "未读合同" },
      { id: "2", logname: "合同申请" },
    ],
    currentTabsIndex: 0,
    guestID:"",
    validate:"0",
    pageSize:5,
    pageIndex:1,
    constracts:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.queryContract();
  },
  onTabsItemTap: function (event) {
    var index = event.currentTarget.dataset.index;
    this.setData({
      currentTabsIndex: index,
      validate:index,
      constracts:[]
    });

    this.queryContract();
  },
  queryContract(){
    let that=this;
    let user=wx.getStorageSync("list");
    that.setData({
      guestID: user.guestid
    });
    app.util.request({
      url: testAddr + "contract/getContractList?validate=" + that.data.validate+"&pageIndex=" + that.data.pageIndex + '&pageSize=' + that.data.pageSize + "&guestID="+that.data.guestID,
      method: "POST",
      data: {},
      success: function (res) {
        console.log(res.data.result);
        let constract = res.data.result;
        constract=JSON.parse(constract);
        that.setData({
          constracts: that.data.constracts.concat(constract)
        });
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that=this;
    that.setData({
      pageIndex:that.data.pageIndex+1
    });
    console.log(that.data.pageIndex);
    that.queryContract();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})